<?php 
/**
 * @file aa.php	Fixed!
 * @version 0.1
 * @desc 交易查询
 */
if(!defined('ACCOUNT_INIT'))
	exit('Access Denied!');

/* 定义全局变量 */
global $gLD;
$user_id = $gLD['user_id'];
$nick = $gLD['user_snick'];

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="zh-CN">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>交易查询</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
</head>
<body oncontextmenu="window.event.returnValue=false">

<table width="617" height="482" border="0" cellpadding="6" cellspacing="0">
  <tr>
    <td valign="top">
<?php  //显示头部文件
    showHeader($gLD['module']); ?>
      <table width="605" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="379" height="436"><table width="371" height="100%" border="0" cellpadding="4" cellspacing="1" bgcolor="#012849">
            <tr>
              <td height="434" valign="top" bgcolor="#4484c1"><table width="361" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="361" height="261" align="left" valign="top">
<div id="Layer1">
                   <table width="361" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td height="28" align="center" valign="bottom" bgcolor="#014075">
                    <table width="318" border="0" cellspacing="0" cellpadding="0">
<tr id="menuTrust">
  <td width="75" height="23" align="center" background="images/tab1.gif"><strong>委托查询</strong></td>
  <td width="6" align="center">&nbsp;</td>
  <td width="75" align="center" background="images/tab2.gif"><a href="#" class="clickDeal">成交查询</a></td>
  <td width="6" align="center">&nbsp;</td>
   <td width="75" align="center" background="images/tab2.gif"><a href="#" class="clickKbao">K宝交易流水</a></td>
   <td width="6" align="center">&nbsp;</td>
   <td width="75" align="center" background="images/tab2.gif"><a href="#" class="clickKbi">K币交易流水</a></td>
</tr>

<tr id="menuDeal">
   <td width="75" height="23" align="center" background="images/tab2.gif"><a href="#" class="clickTrust">委托查询</a></td>
   <td width="6" align="center">&nbsp;</td>
   <td width="75" align="center" background="images/tab1.gif"><strong>成交查询</strong></td>
    <td width="6" align="center">&nbsp;</td>
   <td width="75" align="center" background="images/tab2.gif"><a href="#" class="clickKbao">K宝交易流水</a></td>
   <td width="6" align="center">&nbsp;</td>
   <td width="75" align="center" background="images/tab2.gif"><a href="#" class="clickKbi">K币交易流水</a></td>
</tr> 

<tr id="menuKbao">
   <td width="75" height="23" align="center" background="images/tab2.gif"><a href="#" class="clickTrust">委托查询</a></td>
   <td width="6" align="center">&nbsp;</td>
   <td width="75" align="center" background="images/tab2.gif"><a href="#" class="clickDeal">成交查询</a></td>
    <td width="6" align="center">&nbsp;</td>
   <td width="75" align="center" background="images/tab1.gif"><strong>K宝交易流水</strong></td>
   <td width="6" align="center">&nbsp;</td>
   <td width="75" align="center" background="images/tab2.gif"><a href="#" class="clickKbi">K币交易流水</a></td>
</tr>  

<tr id="menuKbi">
   <td width="75" height="23" align="center" background="images/tab2.gif"><a href="#" class="clickTrust">委托查询</a></td>
   <td width="6" align="center">&nbsp;</td>
   <td width="75" align="center" background="images/tab2.gif"><a href="#" class="clickDeal">成交查询</a></td>
    <td width="6" align="center">&nbsp;</td>
   <td width="75" align="center" background="images/tab2.gif"><a href="#" class="clickKbao">K宝交易流水</a></td>
   <td width="6" align="center">&nbsp;</td>
   <td width="75" align="center" background="images/tab1.gif"><strong>K币交易流水</strong></td>
</tr>          
                  
                    </table></td>
                  </tr>
                </table>                  
<div id="list">            
<table id="listTrust" width="560" border="0" cellspacing="0" cellpadding="0">
  <tr align="center">
    <td width="35" height="24"><span class="STYLE3 blue2">选择</span></td>
    <td width="55"><span class="STYLE3 blue2">业务</span></td>
    <td width="85"><span class="STYLE3 blue2">委托号</span></td>
    <td width="80"><span class="STYLE3 blue2">成交/挂单数</span></td>
    <td width="100"><span class="STYLE3 blue2">K宝单价(K币)</span></td>
    <td width="150"><span class="STYLE3 blue2">挂单日期</span></td>
    <td width="55"><span class="blue2">状态</span></td>
  </tr>
</table>

<table id="listDeal" width="680" border="0" cellspacing="0" cellpadding="0">
	<tr align="center">
        <td width="35" height="24"><span class="STYLE3 blue2">选择</span></td>
        <td width="55"><span class="STYLE3 blue2">业务</span></td>
        <td width="85"><span class="STYLE3 blue2">委托号</span></td>
        <td width="85"><span class="STYLE3 blue2">交易号</span></td>
        <td width="50"><span class="STYLE3 blue2">成交数</span></td>
        <td width="100"><span class="STYLE3 blue2">K宝单价(K币)</span></td>
        <td width="120"><span class="STYLE3 blue2">成交总额</span></td>
        <td width="150"><span class="STYLE3 blue2">挂单日期</span></td>
	</tr>
</table>

<table id="listKbao" width="660" border="0" cellspacing="0" cellpadding="0">
	<tr align="center">
       <td width="85"><span class="STYLE3 blue2">流水号</span></td>
        <td width="55"><span class="STYLE3 blue2">业务</span></td>
        <td width="85"><span class="STYLE3 blue2">委托号</span></td>
        <td width="85"><span class="STYLE3 blue2">交易号</span></td>
        <td width="100"><span class="STYLE3 blue2">K宝成交数</span></td>
        <td width="100"><span class="STYLE3 blue2">K宝结余(K币)</span></td>
        <td width="150"><span class="STYLE3 blue2">挂单日期</span></td>
	</tr>
</table>

<table id="listKbi" width="660" border="0" cellspacing="0" cellpadding="0">
	<tr align="center">
       <td width="85"><span class="STYLE3 blue2">流水号</span></td>
        <td width="55"><span class="STYLE3 blue2">业务</span></td>
        <td width="85"><span class="STYLE3 blue2">委托号</span></td>
        <td width="85"><span class="STYLE3 blue2">交易号</span></td>
        <td width="100"><span class="STYLE3 blue2">K币成交数</span></td>
        <td width="100"><span class="STYLE3 blue2">K币结余(K币)</span></td>
        <td width="150"><span class="STYLE3 blue2">挂单日期</span></td>
	</tr>
</table>

<table id="listKb" border="0" cellspacing="0" cellpadding="0">
<!-- 列表 -->
</table>
</div><!-- #list -->

                <table width="361" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td height="1" bgcolor="#1f5f9c"></td>
                  </tr>
                </table>
                <table width="361" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td height="23" align="center" bgcolor="#3676B4"><table width="90%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td><a id="delKb" href="#"><img src="images/cedan.gif" width="54" height="19" border="0" /></a></td>
                        <td id="page">
                        	<span id="pfirst" ><a href="#">首页</a></span>&nbsp;&nbsp;&nbsp; 
                        	<span id="ppre" ><a href="#">上页</a></span>&nbsp;&nbsp;&nbsp; 
                        	<span id="pnext" ><a href="#">下页</a></span>&nbsp;&nbsp; &nbsp;
                        	<span id="plast" ><a href="#">尾页</a></span>&nbsp;&nbsp;&nbsp; 
                        	<span id="pnow">1/5</span>
                        </td>
                      </tr>
                    </table>                      </td>
                  </tr>
                </table>
</div><!-- #Layer1 -->

                </tr>
              </table>
                <table width="50%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td height="7"></td>
                  </tr>
                </table>
<?php require_once "left.php"; ?> 
</td>
            </tr>
          </table></td>
          <td width="226">
<?php require_once "top.php"; ?>
</td>
        </tr>
      </table></td>
  </tr>
</table>

<script type="text/javascript">
$(document).ready(function(){
	getUserLeft(); //计算用户剩余K
	var f=1; //委托查询
	var page_sum = 1; //总的页数
	var page_now = 1; //当前页数
	var bid = 0; //委托ID
	getlist( bid, 0 ); //得到用户的清单


	//菜单绑定-->成交查询
	$(".clickDeal").click(function(){
		$("#menuTrust").hide();
		$("#listTrust").hide();

		$("#menuKbao").hide();
		$("#listKbao").hide();
		$("#menuKbi").hide();
		$("#listKbi").hide();
		
		$("#menuDeal").show();
		$("#listDeal").show();
		f=2; //成交查询
		getlist( bid, 0 );
	});

	//菜单绑定-->委托查询
	$(".clickTrust").click(function(){
		$("#menuDeal").hide();
		$("#listDeal").hide();

		$("#menuKbao").hide();
		$("#listKbao").hide();
		$("#menuKbi").hide();
		$("#listKbi").hide();
		
		$("#menuTrust").show();
		$("#listTrust").show();
		f=1; //委托查询
		bid = 0; //委托号归零
		getlist( bid, 0 );
	});

	//菜单绑定-->K宝流水查询
	$(".clickKbao").click(function(){
		$("#menuTrust").hide();
		$("#listTrust").hide();
		$("#menuDeal").hide();
		$("#listDeal").hide();

		$("#menuKbi").hide();
		$("#listKbi").hide();
		$("#menuKbao").show();
		$("#listKbao").show();
		
		f=3; //K宝流水查询
		getlist( bid, 0 );
	});

	//菜单绑定-->K币流水查询
	$(".clickKbi").click(function(){
		$("#menuTrust").hide();
		$("#listTrust").hide();
		$("#menuDeal").hide();
		$("#listDeal").hide();

		$("#menuKbao").hide();
		$("#listKbao").hide();
		$("#menuKbi").show();
		$("#listKbi").show();
		
		f=4; //K币流水查询
		getlist( bid, 0 );
	});

	//分页事件绑定
	$("#pfirst").click(function(){
		//alert( page_now );
		getlist( bid, 0 );
	});
	$("#plast").click(function(){
		var offset =  (Number(page_sum)-1)*10;
		getlist( bid, offset );
	});
	$("#ppre").click(function(){
		var offset = 0;
		if( Number(page_now)>2 ){
			offset = (Number(page_now)-2)*10;
		}
		getlist( bid, offset );
	});
	$("#pnext").click(function(){
		var offset = Number(page_now)*10;
		getlist( bid, offset );
	});


	//撤单按钮事件绑定
	$("#delKb").click(function(){
		
		var items =  $("input[name='checkbox']:checked");
		//alert( "选中的个数为："+items.length  );
		var d = 1;
		if( Number(items.length) > 0 ) {
		$.each(items,function(i,n){
			if(d == 1){
				//alert( $(n).val() );
				d = delKb( $(n).val() );
				}
			getlist( bid, 0 ); //刷新列表 
		   	});
		getUserLeft(); //计算用户余额
		} //if items.length > 0
	}); //END $("#delKb").click

	function delKb(kid){
		var re = 0;
		$.post("bg-cc.php", {
			action: 'delKb',
			user_id: '<?php echo $user_id; ?>',
			kid: kid
			}, function(data, textStatus){
				if(data == 1)
					re = 1;
				else if(data == '403'){
					alert("主账户登出K秀系统！");
					window.location='?uin=<?php echo $user_id; ?>&module=login';
				}
			}, 'json');
		return re;
	}//END func delKb

	//得到列表
	function getlist( bid ,offset){
		$.post("bg-list.php", {
			action: 'getlist',
			user_id: '<?php echo $user_id; ?>',
			bid: bid,
			type: f,
			offset: offset
			}, function(data, textStatus){
				//alert(offset);
				addlist( data, offset );
			},'json');
	}//END func getlist


	//添加列表中的项
	function addlist(data, offset){
		//alert(data);
		$("#listKb").empty();
		if(data['msg'] == 1){
			upPage( data['sum'], offset );

			if(f == 1) { //委托查询
				// $("#listDeal").hide();
				// $("#listTrust").show();
				$("#listKb").attr("width","560");
$.each(data['list'], function(i,n){
	var trmsg = '';
	trmsg += "<tr align=\"center\"><td align=\"center\" height=\"25\" width=\"35\"><input name=\"checkbox\" type=\"checkbox\" ";
	if(n['status'] == 0){
		trmsg += " value=\""+ n['bus_id'] +"\" />"; 
	}else{
		trmsg += " disabled=\"true\" value=\""+ n['bus_id'] +"\" />";
	}
	
	trmsg += "</td><td width=\"55\" ";
	if(n['flag'] == 3){
		trmsg += " class=\"blue2\">买入K宝";
	}else if(n['flag'] == 4){
		trmsg += " >卖出K宝";
	}
	trmsg += "</td><td width=\"85\">" +n['bus_id']+ "</td>"
			+ "<td width=\"80\">" +n['num_left']+'/'+n['num']+ "</td>"
			+ "<td width=\"100\">" +n['price']+ "K币</td>"
			+ "<td width=\"150\">" +n['time']+ "</td>"
			+ "<td width=\"55\" ";

	if(n['status'] == 0){
		trmsg += " ><a class=\"detail\" href=\"#\">未成交</a></td></tr>";
	}else if(n['status'] == 1){
		trmsg += " ><a class=\"detail blue3\" href=\"#\">成交</a></td></tr>"; 
	}else if(n['status'] == 6){
		trmsg += " ><a class=\"detail blue3\" href=\"#\">撤单</a></td></tr>"; 
	}else{
		trmsg += " ><a class=\"detail\" href=\"#\">出错</a></td></tr>";
	}

	$("#listKb").append( trmsg );
});

actionDetail(); //为”状态“栏添加点击事件
actionLight();
//alert($("#listKb").html());
			}else if(f == 2 ){ //成交查询
				$("#listKb").attr("width","680");
$.each(data['list'], function(i,n){
	var trmsg = '';
	trmsg = "<tr align=\"center\">";
	trmsg += "<td align=\"center\" height=\"25\" width=\"35\">"
			+ "<input name=\"checkbox\" type=\"checkbox\" disabled=\"true\" value=\""+ n['bus_id'] +"\" />"
			+ "</td>";

	trmsg += "</td><td width=\"55\" ";
	if(n['flag'] == 3){
		trmsg += " class=\"blue2\">买入K宝";
	}else if(n['flag'] == 4){
		trmsg += " >卖出K宝";
	}else if(n['flag'] == 5){
		trmsg += " >委托费";
	}else if(n['flag'] == 6){
		trmsg += " class=\"blue2\">撤单";
	}else if(n['flag'] == 7){
		trmsg += " class=\"blue2\">退返";
	}else{
		trmsg += " >系统";
	}

	trmsg += "</td><td width=\"85\">" +n['bus_id']+ "</td>"
		+ "<td width=\"85\">" + n['pay_id']+ "</td>"
		+ "<td width=\"50\">"+ n['num'] +"</td>"
		+ "<td width=\"100\">"+ n['price'] +"K币</td>"
		+ "<td width=\"120\">"+ n['sum'] +"K币</td>"
		+ "<td width=\"150\">"+ n['time'] +"</td>"
		+ "</tr>";

	$("#listKb").append( trmsg );
});
//alert($("#listKb").html());
actionLight();
			}else if(f == 3){ //K宝交易流水
$("#listKb").attr("width","660");
$.each(data['list'], function(i,n){
	var trmsg = '';
	var d_kao = n['kbao_num'];
	trmsg = "<tr align=\"center\" height=\"25\">"
			+"<td width=\"85\">" + n['pay_id']+ "</td>"
			+"<td width=\"50\" ";
	if(n['flag'] == 1){
		trmsg += " class=\"blue2\">存入";
		d_kao = '+' + d_kao;
	}else if(n['flag'] == 2){
		trmsg += " >取出";
		d_kao = '-' + d_kao;
	}else if(n['flag'] == 3){
		trmsg += " class=\"blue2\">买入K宝";
		d_kao = '+' + d_kao;
	}else if(n['flag'] == 4){
		trmsg += " >卖出K宝";
		d_kao = '-' + d_kao;
	}else if(n['flag'] == 6){
		trmsg += " class=\"blue2\">撤单";
		d_kao = '+' + d_kao;
	}
	trmsg += "</td><td width=\"85\">" +n['bus_id']+ "</td>"
			+"<td width=\"85\">" + n['parent_id']+ "</td>"
			+"<td width=\"100\">"+ d_kao +"K宝</td>"
			+"<td width=\"100\">"+ n['kbao_left'] +"</td>"
			+"<td width=\"150\">"+ n['time'] +"</td>"
			+"</tr>";

	$("#listKb").append( trmsg );
});
actionLight();
			}else if(f == 4){ //K币交易流水
$("#listKb").attr("width","660");
$.each(data['list'], function(i,n){
	var trmsg = '';
	var d_kao = n['kbi_num'];
	trmsg = "<tr align=\"center\" height=\"25\">"
			+"<td width=\"85\">" + n['pay_id']+ "</td>"
			+"<td width=\"55\" ";
	if(n['flag'] == 1){
		trmsg += " class=\"blue2\">存入";
		d_kao = '+' + d_kao;
	}else if(n['flag'] == 2){
		trmsg += " >取出";
		d_kao = '-' + d_kao;
	}else if(n['flag'] == 3){
		trmsg += " >买入K宝";
		d_kao = '-' + d_kao;
	}else if(n['flag'] == 4){
		trmsg += " class=\"blue2\">卖出K宝";
		d_kao = '+' + d_kao;
	}else if(n['flag'] == 5){
		trmsg += " >委托费";
		d_kao = '-' + d_kao;
	}else if(n['flag'] == 6){
		trmsg += " class=\"blue2\">撤单";
		d_kao = '+' + d_kao;
	}else if(n['flag'] == 7){
		trmsg += " class=\"blue2\">返还";
		d_kao = '+' + d_kao;
	}
	
	trmsg += "</td><td width=\"85\">" +n['bus_id']+ "</td>"
			+"<td width=\"85\">" + n['parent_id']+ "</td>"
			+"<td width=\"100\">"+ d_kao +"K币</td>"
			+"<td width=\"100\">"+ n['kbi_left'] +"</td>"
			+"<td width=\"150\">"+ n['time'] +"</td>"
			+"</tr>";

	$("#listKb").append( trmsg );
});
actionLight();
			}// if f查询途径

		}else if(data['msg'] == 2){
			upPage( 0, 0 );
		}
		else{ //msg
			alert("刷新列表错误error: "+data['msg']);
		}
	}//END func addlist


	//修改分页
	function upPage(page, offset){
		//alert(offset);
		
		var sum = 0;
		sum = parseInt( Number(page)/10 );
		if(sum == 0){
			sum = 1;
		}else if( Number(page)%10 > 0 ){
			sum = Number(sum)+1; 
		} //总页数
		var p = parseInt( Number(offset)/10 ) + 1; //当前页数
		page_sum = sum;
		page_now = p;

		$("#pnow").empty();
		$("#pnow").append( p+'/'+sum );
		
		$("#ppre").empty();
		if(  Number(p) > 1 ){
			$("#ppre").append( "<a href=\"#\">上页</a>" );
		}else{
			$("#ppre").append( "上页" );
		}

		$("#pnext").empty();
		if( Number(sum)-Number(p) > 0 ){
			$("#pnext").append( "<a href=\"#\">下页</a>" );
		}else{
			$("#pnext").append( "下页" );
		}

	}//END func upPage

	//委托查询中状态栏的点击事件
	function actionDetail(){

		// 状态按钮事件绑定
		$("#list .detail").click(function(){ //单个委托成交记录
			var bbq = $(this).parent().parent().find('input');
			bid = $(bbq).val(); //记录委托号
			$("#menuTrust").hide(); //委托菜单隐藏
			$("#listTrust").hide();
			$("#menuDeal").show(); //成家菜单显示
			$("#listDeal").show();
			f=2; //成交查询
			getlist( bid, 0 );
		});

	}//END func actionDetail

	// 高亮显示表格
	function actionLight(){
		$("#listKb tr:even").addClass("even");

		//高亮
		$("#listKb tr").click(function(){
			$("#listKb tr").removeClass("trck");
			$("#listKb tr:even").addClass("even");
			$(this).removeClass("even");
			$(this).addClass("trck");
		});
		
	}//END func actionLight
	
	
	//刷新账户余额
	function getUserLeft(){
		$.post("bg-info.php", {
			action: 'getInfo',
			user_id: '<?php echo $user_id; ?>'
			}, function(data, textStatus){
				addInfoMsg( data );
			}, 'json');
	}//END func getUserLeft
	
	function addInfoMsg( data ){
		$("#ikbao-left").empty(); //交易账户
		$("#ikbi-left").empty();
		$("#ikbao-frozen").empty(); //冻结账户
		$("#ikbi-frozen").empty();
		$("#kbi-left").empty(); //本人账户
		$("#kbao-left").empty();
		
		$.each(data['info'], function(i,n){
			$("#ikbao-left").prepend(n['kbao2']); //交易账户
			$("#ikbi-left").prepend(n['kbi2']);
			$("#ikbao-frozen").prepend(n['kbao3']); //冻结账户
			$("#ikbi-frozen").prepend(n['kbi3']);		
			$("#kbi-left").prepend(n['kbi1']);   //prepend(n['kbi1']); //本人账户
			$("#kbao-left").prepend(n['kbao1']);
			});	
	} //END func addInfoMsg
	
}); //END $()

function kDebug( num, left ){
	if( isNull(num) ){
		alert("请输入数字！");
	}else if( !isInteger(num) ){
		alert("输入值必须为数字！");
	}else if( Number(num) > Number(left) ){
		alert("输入值("+ num +")大于账户余额("+ left +")！");
	}else return true;
	return false;
}//END func KDebug

function isNull(vehicleid) {
	if(vehicleid == null || vehicleid == undefined || (!vehicleid))
		return true;
	else return false;
}

function isInteger(str) { 
	   if(/^(\-?)(\d+)$/.test(str)) return true; 
	   else return false; 
}
</script>
</body></html>